Socket
Socket
Sign inDemoInstall

has-value

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

has-value

Returns true if a value exists, false if empty. Works with deeply nested values using object paths.


Version published
Weekly downloads
20M
decreased by-1.78%
Maintainers
1
Weekly downloads
 
Created

What is has-value?

The has-value npm package is used to check if a value exists, is not empty, or is not undefined. It is useful for validating data and ensuring that required fields are populated.

What are has-value's main functionalities?

Check if a value exists

This feature checks if a given value exists. In this example, the string 'Hello World' is checked, and since it is a non-empty string, the result is true.

const hasValue = require('has-value');
console.log(hasValue('Hello World')); // true

Check if an object property has a value

This feature checks if a specific property of an object has a value. In this example, the object has a property 'name' with a value 'John Doe', so the result is true.

const hasValue = require('has-value');
const obj = { name: 'John Doe' };
console.log(hasValue(obj, 'name')); // true

Check if an array has a value

This feature checks if an array has any values. In this example, the array [1, 2, 3] is checked, and since it contains elements, the result is true.

const hasValue = require('has-value');
const arr = [1, 2, 3];
console.log(hasValue(arr)); // true

Check if a nested object property has a value

This feature checks if a nested property within an object has a value. In this example, the nested property 'user.name' is checked, and since it has a value 'Jane Doe', the result is true.

const hasValue = require('has-value');
const nestedObj = { user: { name: 'Jane Doe' } };
console.log(hasValue(nestedObj, 'user.name')); // true

Other packages similar to has-value

Keywords

FAQs

Package last updated on 27 Mar 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc